<?php

#namespace tehframework\annotations\tags;

#use tehframework\testing\phpunit\TestCase;

require_once 'test/testHelper.php';

class AuthorTagTest extends TestCase
{
	const TAG_NAME = 'author';
	const TAG_DOC_STRING = 'foo <someone@the.net>';
	const TAG_AUTHOR = 'foo';
	const TAG_EMAIL  = 'someone@the.net';
	
	/**
	 * @var TagDefinition
	 */
	private $def;
	
	/**
	 * @var AuthorTag
	 */
	private $tag;
	
	protected function beforeTest()
	{
		$this->def = new TagDefinition(self::TAG_NAME, self::TAG_DOC_STRING);
		$this->tag = new AuthorTag($this->def);
	}
	
	function testConstructThrowsExceptionIfInvalidDefinitionWasSpecified()
	{
		$this->setExpectedException('BadMethodCallException');
		
		new AuthorTag(new TagDefinition('hopyfullyImInvalidTagName'));
	}
	
	function testIsSerializable()
	{
		$unserialized = unserialize(serialize($this->tag));
		
		$this->assertSame($this->tag->getName(), $unserialized->getName());
		$this->assertSame($this->tag->getAuthor(), $unserialized->getAuthor());
		$this->assertSame($this->tag->getEmail(), $unserialized->getEmail());
	}
	
	function testGetAuthorReturnsNullIfAuthorWasNotSpecified()
	{
		$tag = new AuthorTag(new TagDefinition(self::TAG_NAME));
		
		$this->assertNull($tag->getAuthor());
	}
	
	function testGetAuthorReturnsDocStringIfItDidNotContainEmail()
	{
		$tag = new AuthorTag(new TagDefinition(self::TAG_NAME, self::TAG_AUTHOR));
		
		$this->assertSame(self::TAG_AUTHOR, $tag->getAuthor());
	}
	
	function testGetEmailReturnsNullIfEmailWasNotSpecified()
	{
		$tag = new AuthorTag(new TagDefinition(self::TAG_NAME, self::TAG_AUTHOR));
		
		$this->assertNull($tag->getEmail());
	}
	
	function testGetEmailReturnsStringEnclosedInAngleBrackets()
	{
		$this->assertSame(self::TAG_EMAIL, $this->tag->getEmail());
	}
	
	function testToString()
	{
		$test = (string)$this->tag;
		
		$this->assertFalse(empty($test));
	}
}